package ru.spb.xmlreshelper.util;

import com.google.common.eventbus.EventBus;
import org.apache.commons.io.FilenameUtils;

import javax.swing.*;
import java.awt.*;

/**
 * @author Nikita.Brazhnikov
 */
public class GuiUtils {

	private static final EventBus guiEventsBus = new EventBus("gui-events-bus");

	public static final EventBus getEventBus() {
		return guiEventsBus;
	}

	public static final void centerFrame(Component c) {
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		int dialogWidth = c.getWidth();
		int dialogHeigth = c.getHeight();
		c.setLocation((d.width / 2) - (dialogWidth / 2), (d.height / 2)
			 - (dialogHeigth / 2));
	}

	public static final String getFileDirectory(String path) {
		return FilenameUtils.getFullPath(path);
	}

	public static void setUpLaF() {
		try {
			UIManager
				 .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Throwable e) {
			try {
				UIManager.setLookAndFeel(UIManager
					                          .getSystemLookAndFeelClassName());
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}
